package com.binarysearch;

public class Solution1351 {
    public int countNegatives(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        int i = m - 1;
        int j = 0;
        int res = 0;
        while (i >= 0 && j < n) {
            if (grid[i][j] >= 0) j++;
            else {
                res += (n - j);
                i--;
            }
        }
        return res;
    }
}
